import type { ClFormModel, CLFormProps } from "../types";

/**
 * form 数据模型类
 */
export const FormModel = (() => {
  let instance: Model | null = null;
  class Model implements ClFormModel {
    public model = ref<Recordable>({});
    #props = ref<CLFormProps>({
      formColumns: [],
      gutter: 20,
    });

    public setProps(newProps: CLFormProps) {
      this.#props.value = newProps;
    }

    public getFormColumns = computed(() => {
      const columns = this.#props.value.formColumns;
      return columns;
    });
    public getGutter = computed(() => this.#props.value.gutter!);
  }

  return {
    getInstance() {
      return instance || (instance = new Model());
    },
  };
})();
